<?php
	require_once('paths.inc');
	require_once(INCLUDE_PATH.'constants.inc');
	require_once('page.inc');
	require_once(DB_PATH.'db.inc');
	
	require_once('security.inc');
	require_once('utils.inc');	
	require_once('time.inc');
			
	session_start();
	check_permissions(null, 'contact.php');
	checkIsLoggedIn();
	
	html_header("LANG_Contact", null, "contact");
	
	$id_client = $_SESSION['user_logat']->id_client;	
	
    $linkuri = array(LANG_Home => "home.php", LANG_Contact => "");	
	titlu_pagina($linkuri);

	output_notice_msg();
	output_error_msg();
	if (isset($_POST['submit'])) {
	
		// VALIDARI
        $nume = $_POST['nume'];
        $nume_firma = $_POST['nume_firma'];
        $telefon = $_POST['telefon'];
        $email_contact = $_POST['email_contact'];
        
		$mesaj = $_POST['mesaj'];
		$tip = $_POST['type_c'];
        
		$corp_mesaj = "Contact primit de la: $nume\n<br>";
        $corp_mesaj .= "e-mail: $email_contact\n<br>";
        $corp_mesaj .= "Nume firma: $nume_firma\n<br>";
		$corp_mesaj .= "Mesajul trimis este:\n\n $mesaj\n<br>";
		
        if ($tip == CT_TECHNICAL_PROBLEMS) $tipul = "PROBLEME TEHNICE";
		if ($tip == CT_OTHER_PROBLEMS) $tipul = "ALTE MOTIVE";

        sendEmailContactFromProgram("Contact - program softy - $tipul", $corp_mesaj);
        /*
		if (($result = @mail($catre, "Contact - program softy - $tipul", $mesaj, 'From: contact@programsofty.com')) !== TRUE)
			$_SESSION["notice_msg"] = LANG_MailSend_Faild;
		else 
        	$_SESSION["notice_msg"] = LANG_Contact_Trimis;
        */
        $_SESSION["notice_msg"] = LANG_Contact_Trimis;
	}
    output_notice_msg();
    output_extra_text(LANG_EXTRA_CONTACT);    
?>
	<script type="text/javascript">
		function validateForm() {
			return (validatePrintable(document.contact.nume.value, '<?php echo LANG_nume; ?>', true, 2) &&
						validatePrintable(document.contact.nume_firma.value, '<?php echo LANG_NUME_FIRMA; ?>', false, 5) &&
						validatePrintable(document.contact.telefon.value, '<?php echo LANG_TELEFON; ?>', false) &&
						validateMail(document.contact.email_contact.value, true) &&
						validatePrintable(document.contact.mesaj.value, '<?php echo LANG_Contact_Mesaj; ?>', true, 10));
		}
	</script>
		
		
	<form action="contact.php" method="POST" name="contact" onsubmit="return (validateForm());">
		<table align="left">
			<tr>
				<td valign="top">
					<table align="left" id="wrapper">
						<thead>
							<tr>
								<th><?php echo LANG_Contact_Type; ?></th>
							</tr>
						</thead>
						<tbody align="left">
                            <tr class="capTabel">                            
                                <td>                            
                                    <label>
                                        <input type="radio" name="type_c" value="<?php echo CT_TECHNICAL_PROBLEMS; ?>" /> <?php echo LANG_TECHNICAL_PROBLEMS; ?>
                                    </label>
                                    <br />
                                    <label>
                                        <input type="radio" checked="checked" name="type_c" value="<?php echo CT_OTHER_PROBLEMS; ?>" /> <?php echo LANG_OTHER_REASON; ?>
                                    </label>
                                </td>                            
							</tr>                            
						</tbody>
					</table>			
				</td>
				<td valign="top">
					<table align="left" id="wrapper">
						<thead>
							<tr>
								<th align="center" colspan="2"><?php echo LANG_Contact; ?></th>
							</tr>
						</thead>
						<tbody>
                            <tr class="capTabel">
                                <td><?php echo LANG_nume . CT_OBLIGATORIU; ?></td>
                                <td><input name="nume" type="text" value="<?php echo $_SESSION['user_logat']->nume . " " . $_SESSION['user_logat']->prenume; ?>" /></td>
                            </tr>                            
                            <tr class="capTabel">
                                <td><?php echo LANG_NUME_FIRMA; ?></td>
                                <td><input name="nume_firma" type="text" value="<?php echo $_SESSION['client_logat']->nume; ?>" /></td>
                            </tr>                            
                            <tr class="capTabel">
                                <td><?php echo LANG_TELEFON; ?></td>
                                <td><input name="telefon" type="text" value="<?php echo $_SESSION['client_logat']->tel_fix; ?>" /></td>
                            </tr>
                            <tr class="capTabel">
                                <td><?php echo LANG_EMAIL_CONTACT . CT_OBLIGATORIU; ?></td>
                                <td><input name="email_contact" type="text" value="<?php echo $_SESSION['client_logat']->email; ?>" /></td>
                            </tr>
							<tr class="capTabel">
								<td><?php echo LANG_Enter_you_question_here . CT_OBLIGATORIU; ?></td>
								<td>
									<textarea rows="7" cols="50" name="mesaj"><?php if (isset($_POST['mesaj'])) echo $_POST['mesaj']; ?></textarea>
								</td>
							</tr>
							<tr class="capTabel">
								<td></td>
								<td><input type="submit" name="submit" value="<?php echo LANG_Send_Message; ?>" /></td>
							</tr>
						</tbody>
					</table>			
				</td>
			</tr>
		</table>
	</form>

<?php
	html_footer();
?>